<?php 

/**
 * 商品类型控制器
 */
class TypeController extends AuthController{
	
	private $model;
    
	public function __init(){
	    $this->model = K('Type');
	}
	
	 /* 
	 ***
     *  类型首页
     */
    public function index(){
    		$this->assign('data', $this->model->all());		
       	$this->display(); 
    }
	
	// 添加类型
	public function add(){
		if (IS_POST){
			if (!$this->model->addData()) {
				$this->error($this->model->error);
			}
			$this->success("添加商品类型成功", U('Index'));
		}
	    $this->display();
	}
	
	// 修改类型
	public function edit(){
		if (IS_POST){
			if (!$this->model->editData()){
				$this->error($this->model->error);
			}
			$this->success("修改商品类型成功", U('Index'));
		}
		$tid = Q('get.tid', 0, 'intval');
		$this->assign('oldData', $this->model->where("tid={$tid}")->find());
	    $this->display();
	}
	
	// 删除类型
	public function del(){
		$tid = Q('get.tid', 0, 'intval');
		if (!$this->model->where("tid={$tid}")->delete()){
			$this->error($this->model->error);
		}
		$this->success("删除商品类型成功", U('Index'));
	}
 }
 
 
 
 
 
 
 
 
 
 
 


 ?>